package com.shop.service;

import com.shop.dao.UserDao;
import com.shop.dao.UserDaoImpl;
import com.shop.pojo.User;
import com.shop.util.Constants;
import com.shop.util.MD5Utils;

public class UserServiceImpl implements UserService{
    @Override
    public User login(String username, String password) {
        UserDao userDao = new UserDaoImpl();
        User user =userDao.findByusername(username);
        if(user == null){
            return null;
        }
        if(Constants.USER_NOT_ACTIVE.equals(user.getStatus())){
            return null;
        }
        if(Constants.ROLE_CUSTOMER != user.getRole()){
            return null;
        }
        String md5Pwd = MD5Utils.md5(password);
        if(md5Pwd.equals(user.getPassword())){
            return user;
        }
        return null;
    }
}
